package org.example.demo;



import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.example.task.ConnectElasticsearch;
import org.example.task.ElasticsearchTask;



/**
 * @Author wangf
 * @Description TODO 查询文档
 * @Date 2023/3/2 17:27
 */
public class GetDoc {
    public static void main(String[] args) {
        ConnectElasticsearch.connect(new ElasticsearchTask() {
            @Override
            public void doSomething(RestHighLevelClient client) throws Exception {
                // 1.创建请求对象
                GetRequest request = new GetRequest().index("user").id("1001");
                // 2.客户端发送请求，获取响应对象
                GetResponse response = client.get(request, RequestOptions.DEFAULT);
                // 3.打印结果信息
                System.out.println("_index:" + response.getIndex());
                System.out.println("_type:" + response.getType());
                System.out.println("_id:" + response.getId());
                System.out.println("source:" + response.getSourceAsString());
            }
        });
    }
}
